import Vue from 'vue'
import Router from 'vue-router'
import index from './views/index.vue'
import login from './views/login.vue'
import resetpassword from './views/resetpassword.vue'
import user from './views/forum/user.vue'
const components = {
    Forum: () =>
        import('@/forum/views/forum'),
    Article: () =>
        import('@/forum/views/forum/article'),
    Posted: () =>
        import('@/forum/views/forum/posted'),
    Detail: () =>
        import('@/forum/views/forum/detail'),
    Reply: () =>
        import('@/forum/views/forum/reply'),
    Collect: () =>
        import('@/forum/views/forum/collect'),
    Draft: () =>
        import('@/forum/views/forum/draft'),
    Information: () =>
        import('@/forum/views/forum/information'),
    Editor: () =>
        import('@/forum/views/forum/editor')
}


import {
    get
} from "jquery"
Vue.use(Router)

export default new Router({
    routes: [{
        path: '/',
        name: 'index',
        component: index,
        redirect: '/forum',
        children: [{
            path: '/posted',
            name: 'posted',
            component: components.Posted
        },
        {
            path: '/forum',
            name: 'forum',
            component: components.Forum
        },
        {
            path: '/detail/:id',
            name: 'detail',
            component: components.Detail,
            props: true
        },
        {
            path: '/editor/:id',
            name: 'editor',
            component: components.Editor,
            props: true
        },
        {
            path: '/collect',
            name: 'collect',
            component: components.Collect,
        },

        ]
    },


    {
        path: '/user/:uid',
        name: 'user',
        component: user,
        props: true
    },

    {
        path: '/login',
        name: 'login',
        component: login
    },
    {
        path: '/resetpassword',
        name: 'resetpassword',
        component: resetpassword
    },

    {
        //服务器退出 
        path: '/logout',
        name: 'logout',
        beforeEnter: function () {
            get("/user/logout")
            location.href = '/'
        }
    },
    ]
});